<template>
  <div class="login-container">
    <div class="left" />
    <div class="right">
      <h1>登录</h1>
      <div class="form-container">
        <el-form ref="form" :model="form" :rules="rules">
          <el-form-item prop="mobile">
            <el-input v-model="form.mobile" clearable placeholder="请输入手机号" />
          </el-form-item>
          <el-form-item prop="password">
            <el-input v-model="form.password" show-password placeholder="请输入密码" />
          </el-form-item>
          <el-form-item>
            <el-checkbox v-model="checked">用户平台使用协议</el-checkbox>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" class="dl-button" @click="dl('form')">登录</el-button>
          </el-form-item>
          <el-form-item style="color:red;">
            仅用于IT培训教学使用,为保障您的个人信息安全，请勿向平台录入任何个人敏感信息 (如手机号、身份证号等)!
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
// import axios from 'axios'
import request from '@/utils/request'
export default {
  name: 'LoginClod',
  data() {
    var mima = (rule, value, callback) => {
      const reg = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/
      if (!reg.test(value)) {
        callback(new Error('请输入正确的手机号'))
      } else {
        callback()
      }
    }
    return {
      form: {
        mobile: process.env.NODE_ENV === 'development' ? '13800000002' : '',
        password: process.env.NODE_ENV === 'development' ? 'hm#qd@23!' : ''
      },
      checked: false,
      rules: {
        mobile: [
          { required: true, message: '请输入手机号', trigger: 'blur' },
          { validator: mima, trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 16, message: '请输入长度为6-16位的密码', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
  },
  created() {
  },
  methods: {
    dl(formName) {
    // 点击登录，判断  checked，如果为true才能
      if (!this.checked) {
        this.$message.error('请勾选协议')
        return
      }
      // 兜底校验
      this.$refs[formName].validate(async(valid) => {
        if (valid) {
          // 成功走
          await this.$store.dispatch('user/loginAction', this.form)
          this.$message.success('登录成功')
          this.$router.push('/example')
          // axios.post('https://heimahr.itheima.net/api/sys/login', this.form).then(res => {
          //   console.log(res)
          // })
          // const res = await request.post('/sys/login', this.form)
          // console.log(res)
        }
      })
    }
  }
}
</script>
<style lang='scss'  scoped>
.login-container{
  display: flex;
// background-color: red;
width: 100vw;
height: 100vh;
.left{
  flex: 3;
  background-color: pink;
  padding: 0 70px;
  background: red url('../../assets/common/login_back.png') no-repeat center/cover;
  border-radius: 0 70px 0 0;
}
.right{
  flex: 2;
  // background-color: blue;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  // width: 100%;
  .form-container{
    width: 70%;
    .dl-button{
      width: 100%;
    }
  }
}
}
</style>
